package StatusAuthorization

import (
	"ToolLibray/jwtx"
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
	"property_api/internal/svc"
	"property_api/internal/types"
	"property_api/utils/result"
	"property_service/property_service"
)

type StatusAuditUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStatusAuditUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusAuditUserLogic {
	return &StatusAuditUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StatusAuditUserLogic) StatusAuditUser(req *types.AuditUser) (resp *types.Response, err error) {
	// 设置租户ID，从上下文中获取
	tenantID := jwtx.GetUserTenantId64(l.ctx)
	// 设置更新用户，从上下文中获取
	userIdStr := jwtx.GetUserId(l.ctx)

	// 调用服务层方法，添加资产出库记录
	// 服务层方法 StatusAuthorization 会处理实际的数据库插入操作
	res, err := l.svcCtx.BasicService.StatusAuditUser(l.ctx, &property_service.AuditUser{
		TenantID:        tenantID,            // 租户ID
		UserID:          userIdStr,           // 记录ID
		StatusCode:      req.StatusCode,      // 状态代码
		StatusName:      req.StatusName,      // 状态名称
		UserName:        req.UserName,        // 用户名
		Description:     req.Description,     //操作类型  同意/拒绝
		StatusGroup:     req.StatusGroup,     // 状态分组
		StatusGroupName: req.StatusGroupName, // 状态分组名称
		Status:          req.Status,          // 状态
		OperationType:   req.OperationType,   // 更新人
	})
	fmt.Println("res", res)
	// 如果服务层返回错误，返回统一的错误响应
	if err != nil {
		return result.Err(err).End()
	}

	resp, err = result.Suc(res).End()
	//获取调用返回的id
	resp.Data = map[string]any{
		"StatusCode": res.StatusCode,
		"StatusName": res.StatusName,
	}
	// 返回成功的响应
	return resp, err
}
